import { msgContentList, retryMsgSend } from '@/services/manageMsg';
import Prompt from '@/components/Prompt';

export default {
  namespace: 'content',

  state: {
    msgContentList: {},
  },

  effects: {
    *msgContentList({ payload, callback }, { call, put }) {
      const response = yield call(msgContentList, payload);
      if (response.code === 0) {
        const { list, pageSize, total, pageNum } = response.data;
        yield put({
          type: 'show',
          payload: {
            msgContentList: {
              pagination: {
                current: pageNum,
                pageSize,
                total,
              },
              list,
            },
          },
        });
        callback && callback(list);
      }
    },
    *retryMsgSend({ payload, callback }, { call, put }) {
      const response = yield call(retryMsgSend, payload);
      const { code, data, message } = response;
      if (code === 0) {
        Prompt({ content: `发送${message}` });
        callback && callback(data);
      }
    },
  },

  reducers: {
    show(state, { payload }) {
      return {
        ...state,
        msgContentList: payload.msgContentList,
      };
    },
  },
};
